package com.gesee.zyspps.adapter;

import java.util.ArrayList;
import java.util.List;

import com.gesee.zys.R;
import com.gesee.zyspps.adapter.LeibieAdapter.ViewHolder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;
import android.widget.TextView;

/**
 * 
 * @ClassName: MainSpinnerAdapter
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author fujianxiong
 * @date 2015-8-29 下午1:08:12
 * 
 */

// 格式化代码： ctrl+shift+F 你自己试试
public class MainSpinnerAdapter extends BaseAdapter
{

    private Context context;
    private List list = new ArrayList();
    private LayoutInflater mInflater;

    public MainSpinnerAdapter(Context context)
    {
        this.context = context;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount()
    {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int position)
    {
        // TODO Auto-generated method stub
        return list.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        // TODO Auto-generated method stub
        return 0;
    }

    public void addData(List list)
    {
        this.list.addAll(list);
        notifyDataSetChanged();
    }

    public void cleanData()
    {
        this.list.clear();
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        // TODO Auto-generated method stub
        ViewHolder holder = null;
        if (convertView == null)
        {
            convertView = mInflater.inflate(R.layout.item_main_spinner, null);
            holder = new ViewHolder();
            holder.tv_Value = (TextView) convertView.findViewById(R.id.data);
            convertView.setTag(holder);
        }
        else
        {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_Value.setText(list.get(position).toString().trim());
        return convertView;
    }

    static class ViewHolder
    {
        TextView tv_Value;
    }

}
